import * as types from './actionTypes';

const defaultState = {
	inputValue: "Write Something",
	list: [
		"早8点开晨会，分配今天的代码任务",
		"早9点和项目经理开需求沟通会",
		"早9点和项目经理开需求沟通会",
	],
};

const func = (state = defaultState, action) => {
	console.log(state, action);
	let newState = JSON.parse(JSON.stringify(state));
	console.log("newState :>> ", newState);
	// Reducer里只能接受state,不能改变state
	switch (action.type) {
		case types.ADD_ITEM:
			newState.list.push(newState.inputValue);
			newState.inputValue = "";
			return newState;
		case types.CHANGE_INPUT:
			newState.inputValue = action.value;
			return newState;
		case types.DELETE_ITEM:
			newState.list.splice(action.index, 1);
			return newState;
		case types.GET_LIST:
			newState.list = action.data.data.list;
			return newState;
		default:
			break;
	}

	return state;
};

export default func;
